package com.lenovo.rc.sil.wangdwa.learning;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CompoundLayoutDemoActivity extends Activity implements OnClickListener{
	
	Button btnInit = null;
	Button btnAct = null;
	Button btnUninit = null;
	
	EditText txtData = null;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnInit = (Button) findViewById(R.id.BTN_INIT);
        btnAct = (Button)findViewById(R.id.BTN_ACT);
        btnUninit = (Button)findViewById(R.id.BTN_UNINIT);
        
        btnInit.setOnClickListener(this);
        btnAct.setOnClickListener(this);
        btnUninit.setOnClickListener(this);
        
        txtData = (EditText)findViewById(R.id.TXT_DATA);
        
        
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.BTN_INIT:
			doInit();
			break;
		case R.id.BTN_ACT:
			doAct();
			break;
		case R.id.BTN_UNINIT:
			doUninit();
			break;
		}
	}

	private void doUninit() {
		// TODO Auto-generated method stub
		printText("Uninitializing....");
		
		btnUninit.setEnabled(false);
		btnInit.setEnabled(true);
	}

	private void doAct() {
		// TODO Auto-generated method stub
		clearText();
	}

	private void doInit() {
		// TODO Auto-generated method stub
		printText("Initializing....");
		btnInit.setEnabled(false);
		btnUninit.setEnabled(true);
	}
	
	private void clearText() {
		txtData.setText("");
	}
	
	private void printText(String data) {
		txtData.append(data);
		txtData.append("\n\n");
		txtData.append("---------------");
	}
}